package com.dingup.provider.init;

import com.alibaba.fastjson.JSONObject;
import com.dingup.api.Util.RedisUtils;
import com.dingup.api.model.sys.SysPermission;
import com.dingup.provider.service.sys.SysPermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by wancheng on 2018/8/9.
 */
@Component
@Order(1)
public class PermissionUrlInitController implements CommandLineRunner {

    private static Logger logger = LoggerFactory.getLogger(PermissionUrlInitController.class);

    @Autowired
    SysPermissionService sysPermissionService;
    @Override
    public void run(String... strings) throws Exception {
        List<SysPermission> permissions = sysPermissionService.getAllPermission();
        RedisUtils.getInstance().setPermissionUrl(permissions);
        logger.info("项目启动,初始化加载url资源 permission={}", JSONObject.toJSONString(permissions));
    }
}
